#!/bin/bash
#set -e
COL='\033[1;32m'
NC='\033[0m' # No Color
echo -e "${COL}Setting up klipper"

echo -e "${COL}Installing dependencies...\n${NC}"
apk add python3-dev build-base gcc g++ py3-cffi py3-greenlet linux-headers can-utils git libusb-dev ncurses-dev libffi-dev avrdude gcc-avr binutils-avr avr-libc stm32flash newlib-arm-none-eabi gcc-arm-none-eabi binutils-arm-none-eabi libusb pkgconfig

echo -e "${COL}Downloading klipper\n${NC}"
git clone https://gitee.com/miroky/klipper.git

#echo -e "${COL}Extracting klipper\n${NC}"
mv klipper /klipper
pip install virtualenv
rm /usr/lib/python3.9/site-packages/distlib-0.3.1-py3.9.egg-info
pip install virtualenv
virtualenv /klipper-env
source /klipper-env/bin/activate
pip install -r /klipper/scripts/klippy-requirements.txt
deactivate
mkdir /root/klipper_config
echo "# replace with your config" >> /root/klipper_config/printer.cfg

echo -e "${COL}\nKlipper installed!${NC}"
